﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Text;

namespace Tizer.Core.Repository
{
    /// <summary>
    /// Хранилище городов
    /// </summary>
    public class CityRepository : BaseRepository<City>
    {
        public CityRepository(ObjectContext context)
            : base(context)
        {
        }

        public CityRepository()
        {
        }

        /// <summary>
        /// Получить сущность по Id
        /// </summary>
        /// <returns>Сущность</returns>
        public City GetById(int id)
        {
            return ObjectSet.SingleOrDefault(e => e.ID == id);
        }

        /// <summary>
        /// Удалить 
        /// </summary>
        /// <param name="id">ID</param>
        public void Delete(int id)
        {
            City city = Single(x => x.ID == id);
            if (city == null) return;
            Delete(city);
            SaveChanges();
        }
    }
}
